﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using System.Net;
using System.IO;
using System.Text.RegularExpressions;
using MM.DBUtility;
using MM.Common;

namespace MobileManager.Other
{
    public partial class OrderInfo : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string strUserAgent = Request.UserAgent;
                //HttpCookieCollection hcc = Request.Cookies;
                string strContentType = Request.ContentType;
                //string[] argAcceptTypes = Request.AcceptTypes;
                //HttpClientCertificate hcCertificate = Request.ClientCertificate;
                //System.Collections.Specialized.NameValueCollection nvc = Request.Headers;

                string strURL1 = "http://wap.cmread.com/iread/wml/p/kzdsqg10.jsp?nid=360541130&cm=36679";
                string strResponse1 = ComHelper.GetWebResponse(strURL1, strUserAgent, strContentType);

                if (!string.IsNullOrEmpty(strResponse1))
                {
                    string strReg1 = "<a href=\"([^,]*)[^>]*\">(我要订购)</a>";

                    string strURL2 = string.Empty;
                    foreach (Match m1 in Regex.Matches(strResponse1, strReg1, RegexOptions.IgnoreCase))
                    {
                        strURL2 = m1.Groups[1].Value;
                        break;
                    }

                    if (!string.IsNullOrEmpty(strURL2))
                    {
                        string strResponse2 = ComHelper.GetWebResponse("http://wap.cmread.com" + strURL2, strUserAgent, strContentType);

                        if (!string.IsNullOrEmpty(strResponse2))
                        {
                            string strReg2 = "<a href=\"([^,]*)[^>]*\">(确认订购)</a>";
                            string strURL3 = string.Empty;
                            foreach (Match m2 in Regex.Matches(strResponse2, strReg2, RegexOptions.IgnoreCase))
                            {
                                strURL3 = m2.Groups[1].Value;
                                break;
                            }

                            if (!string.IsNullOrEmpty(strURL3))
                            {
                                //HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://wap.cmread.com" + strURL3);
                                //myReq.Method = "POST";
                                //myReq.UserAgent = strUserAgent;
                                //myReq.ContentType = strContentType;
                                //myReq.GetResponse();

                                //Response.Redirect("http://wap.cmread.com" + strURL3.Replace("l/buySalesPackage.jsp", "p/index.jsp"));

                                divInfo.InnerHtml = string.Format("<a href=\"{0}\" style=\"text-decoration: none;\" target=\"_self\">返 回</a>", "http://wap.cmread.com" + strURL3);
                            }
                        }
                    }

                }
            }
        }
    }
}
